package org.edu.modules.veTeachCourse.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import org.edu.common.api.vo.Result;
import org.edu.common.aspect.annotation.AutoLog;
import org.edu.common.system.base.controller.BaseController;
import org.edu.common.system.query.QueryGenerator;
import org.edu.modules.veTeachCourse.entity.VeTeachCourse;
import org.edu.modules.veTeachCourse.service.IVeTeachCourseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags={"教学课程表相关"})
@RestController
@RequestMapping({"/course/veTeachCourse"})
public class VeTeachCourseController
        extends BaseController<VeTeachCourse, IVeTeachCourseService>
{
    private static final Logger log = LoggerFactory.getLogger(VeTeachCourseController.class);
    @Autowired
    private IVeTeachCourseService veTeachCourseService;
    @Value("${edu.path.urlPre}")
    private String fileUrlPre;

    @AutoLog("教学课程表相关-分页列表查询")
    @ApiOperation(value="教学课程表相关-分页列表查询", notes="教学课程表相关-分页列表查询")
    @GetMapping({"/list"})
    public Result<?> queryPageList(VeTeachCourse veTeachCourse, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req)
    {
        QueryWrapper<VeTeachCourse> queryWrapper = QueryGenerator.initQueryWrapper(veTeachCourse, req.getParameterMap());
        Page<VeTeachCourse> page = new Page(pageNo.intValue(), pageSize.intValue());
        IPage<VeTeachCourse> pageList = this.veTeachCourseService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    @AutoLog("教学课程表相关-添加")
    @ApiOperation(value="教学课程表相关-添加", notes="教学课程表相关-添加")
    @PostMapping({"/add"})
    public Result<?> add(@RequestBody VeTeachCourse veTeachCourse)
    {
        this.veTeachCourseService.save(veTeachCourse);
        return Result.OK("添加成功！");
    }

    @AutoLog("教学课程表相关-编辑")
    @ApiOperation(value="教学课程表相关-编辑", notes="教学课程表相关-编辑")
    @PutMapping({"/edit"})
    public Result<?> edit(@RequestBody VeTeachCourse veTeachCourse)
    {
        this.veTeachCourseService.updateById(veTeachCourse);
        return Result.OK("编辑成功!");
    }

    @AutoLog("教学课程表相关-通过id删除")
    @ApiOperation(value="教学课程表相关-通过id删除", notes="教学课程表相关-通过id删除")
    @DeleteMapping({"/delete"})
    public Result<?> delete(@RequestParam(name="id", required=true) String id)
    {
        this.veTeachCourseService.removeById(id);
        return Result.OK("删除成功!");
    }

    @AutoLog("教学课程表相关-批量删除")
    @ApiOperation(value="教学课程表相关-批量删除", notes="教学课程表相关-批量删除")
    @DeleteMapping({"/deleteBatch"})
    public Result<?> deleteBatch(@RequestParam(name="ids", required=true) String ids)
    {
        this.veTeachCourseService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    @AutoLog("教学课程表相关-通过id查询")
    @ApiOperation(value="教学课程表相关-通过id查询", notes="教学课程表相关-通过id查询")
    @GetMapping({"/queryById"})
    public Result<?> queryById(@RequestParam(name="id", required=true) String id)
    {
        VeTeachCourse veTeachCourse = (VeTeachCourse)this.veTeachCourseService.getById(id);
        if (veTeachCourse == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(veTeachCourse);
    }
}
